package br.com.android.pubclub.web;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import br.com.android.pubclub.R;
import br.com.android.pubclub.basicas.Promocao;

public class PromocoesAdapter extends BaseAdapter{

private ArrayList<Promocao> listaDePromos;
	
	
	public PromocoesAdapter(ArrayList<Promocao> listaDePromos){
		
		this.listaDePromos = listaDePromos;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return listaDePromos.size();
	}

	@Override
	public Promocao getItem(int position) {
		// TODO Auto-generated method stub
		return listaDePromos.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return listaDePromos.get(position).hashCode();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		
		   Holder holder;  
		   Context ctx = parent.getContext();
		   
		   Promocao pro = listaDePromos.get(position);  
		  
		   if (convertView == null){  
			   
		      convertView = LayoutInflater.from(ctx).inflate(  
		        R.layout.lista_de_promocoes_linha, null);  
		   
		      holder = new Holder();  
		      holder.txtTituloPromo = (TextView)   
		         convertView.findViewById(R.id.txtTituloPromo);  
		      holder.txtDescPromo = (TextView)   
		         convertView.findViewById(R.id.txtDescPromo);  
		      convertView.setTag(holder);  
		   } else {  
		      holder = (Holder)convertView.getTag();  
		   }  
		   holder.txtTituloPromo.setText(pro.getTitulo());  
		   holder.txtDescPromo.setText(pro.getDescricao());  
		  
		   return convertView;  
		
		
		
		
		
	}
	
	static class Holder {
	
		TextView txtTituloPromo;
		TextView txtDescPromo;
		
	}
		}
